package com.qianyu.project.web.controller.gs;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianyu.project.entity.TenderPurchasePlan;
import com.qianyu.project.service.ITenderPurchasePlanService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import com.qianyu.project.vo.TenderPurchasePlanExtend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author gs
 * @date create in 2021/2/1 10:55
 */
@RestController
@RequestMapping("/tenderPurchasePlans")
public class TenderPurchasePlanController {

    @Autowired
    private ITenderPurchasePlanService tenderPurchasePlanService;

    @GetMapping("/page")
    public Result getPageList(@RequestParam Map<String, String> params) {
        return ResultTool.success(tenderPurchasePlanService.getPageList(params));
    }

    @GetMapping("/code")
    public Result getMaxCode() {
        return ResultTool.success(Long.parseLong(tenderPurchasePlanService.getMaxCode()) + 1);
    }

    @PostMapping
    public Result save(@RequestBody TenderPurchasePlanExtend tenderPurchasePlanExtend) {
        tenderPurchasePlanService.saveWithDetails(tenderPurchasePlanExtend.getTenderPurchasePlan(), tenderPurchasePlanExtend.getTenderPurchaseDetails());
        return ResultTool.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable String id) {
        return ResultTool.success(tenderPurchasePlanService.getById(id));
    }

    @GetMapping
    public Result getList() {
        return ResultTool.success(tenderPurchasePlanService.list(
                new QueryWrapper<TenderPurchasePlan>()
                .eq("approve_status", "3")
        ));
    }
}
